<div class="headertitle">
    <label><h2>Foto Album</h2></label>
</div>
<?php
$prefix = "";
if (isset($_GET['ajax'])) {
    session_start();
    $prefix = "../";
}

include_once $prefix . 'controller/registrasi.php';
include_once $prefix . 'controller/login.php';
include_once $prefix . 'controller/follow.php';
include_once $prefix . 'controller/admin.php';
include_once $prefix . 'controller/message.php';
?>
<?php
if (isset($_GET['name_viewed'])!= NULL) {
    $name_viewed = $_GET['name_viewed'];
}
else if (isset($_SESSION['user_name'])!= NULL) {
    $name_viewed = $_SESSION['user_name'];
}
if (isset($_SESSION['user_name'])!= NULL) {
    $name_logon = $_SESSION['user_name'];
    $temp = new login();
    $role = $temp->getRole($name_logon );
}
else {
    $name_logon = NULL;
    $role = NULL;
}
?>
<?php
if(isset ($_POST['submit_button_upload'])) {
    $photo = new photo();
    $result = $photo->upload($_SESSION['user_name'], $_POST['dekripsi'], $_POST['kata_kunci'], $_POST['tanggal'], $_POST['kategori'], $_POST['penglihat'], $_POST['penglihatKom'], $_FILES['fileFoto']);
}
if(isset ($_GET['delete']) && isset ($_GET['url_foto'])) {
    if($_GET['delete']=='yes' && ($name_logon == $name_viewed || $role == 'admin')) {
        $deletePhoto = new photo();
        $deletePhoto->deletePhoto($name_logon, $_GET['url_foto']);
    }
}
?>
<div class="isipagestandar">
    <div>
        <?php
        if($_SESSION['user_name'] == $name_viewed) {
            echo'<a href="upload_foto.php?name_viewed='.$name_logon.'">Upload New Photo</a>';
        }
        ?>
    </div>
    <div class="space">

    </div>
    <div>
        <div>
            <?php
            $photo2 = new photo();
            $result = $photo2->showPhotoByName($name_viewed);
            $iterate=0;
            while($row = mysql_fetch_array($result)) {
                $fol = new follow();
                if ($row['photo_prev'] == 'login_user') {
                    if ($name_logon == NULL) {
                        continue;
                    }
                }else if ($row['photo_prev'] == 'owner') {
                    if ($name_logon != $row['user_name']) {
                        continue;
                    }
                }else if ($row['photo_prev'] == 'follower_user') {
                    $follow = $fol->isFollowing($row['user_name'], $name_logon);
                    if ($name_logon == $row['user_name']) {

                    }else if (!$follow) {
                        continue;
                    }
                }
                ?>
            <div class="floatleft" id="photogallery">
                    <?php
                    $iterate++;
                    $urlProfile = "foto_zoom.php?name_viewed=" . $row['user_name'];
                    ?>
                <a href="<?php echo $urlProfile.'&url_foto='.$row['url_photo'] ?>" >
                    <img id="<?php echo "foto_" . $iterate?>" name="<?php echo "foto_" . $iterate?>" src="<?php echo $row['url_photo'] ?>" alt="<?php echo "foto_" . $iterate?>" width="100" height="100" border="0"/>
                </a>
                <div>
                    <label><?php echo $row['key_word'] ?></label>
                </div>

            </div>
                <?php } ?>
        </div>

    </div>
    <?php
    if (isset ($_POST['submit_button_upload'])) {
        echo'
        <div id="fb-root"></div>

        <script>
            FB.init({
                appId:"205313469486760", cookie:true,
                status:true, xfbml:true
            });

            FB.ui({ method: "feed",
                message: "'.$name_logon.' baru saja upload foto di PotoBut, lontong mau juga?"});
        </script>';
    }
    ?>
</div>